package com.zhongwang.mms.module.half.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.gen.entity.User;
import com.zhongwang.mms.module.half.model.HInventoryQueryModel;
import com.zhongwang.mms.module.half.model.HProjectInventoryMarkModel;
import com.zhongwang.mms.module.half.service.ProToInvMarkService;
import com.zhongwang.mms.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @description:项目划库存标记
 * @author: th
 * @time: 2020/5/12 9:33
 */
@Controller
@RequestMapping("/half/halInvManage/proToInvMark")
public class ProToInvMarkController extends BaseController {

    //页面文件路径
    private String prefix = "half/halInvManage/proToInvMark";
    @Autowired
    private ProToInvMarkService proToInvMarkService;

    /**
     * 加载页面
     *
     * @param model
     * @return
     */
    @GetMapping("/page")
    @RequiresPermissions({"halinv:halprowar:view"})
    public String create(Model model) {

        // 获取登入用户实体
        User user = ShiroUtils.getUser();
        model.addAttribute("userName", user.getName());
        return prefix + "/page";
    }

    /**
     * 加载页面数据
     * @param query
     * @return
     */
    @ResponseBody
    @PostMapping("/applyList")
    @RequiresPermissions({"halinv:halprowar:view"})
    public JsonResult applyList(HProjectInventoryMarkModel query) {

        startPage();
        List<HProjectInventoryMarkModel> list = proToInvMarkService.applyList(query);
        return jsonResult(list);
    }
    /**
     * 跳转新增标记页面
     * @param model
     * @return
     */
    @GetMapping("/createPage")
    @RequiresPermissions({"halinv:halprowar:view"})
    public String createPage(Model model) {

        // 获取登入用户实体
        User user = ShiroUtils.getUser();
        model.addAttribute("userName", user.getName());
        return prefix + "/createPage";
    }

    /**
     * 新增标记加载数据
     * @param query
     * @return
     */
    @ResponseBody
    @PostMapping("/inventoryList")
    @RequiresPermissions({"halinv:halprowar:edit"})
    public JsonResult inventoryList(HInventoryQueryModel query) {

        startPage();
        return jsonResult(proToInvMarkService.getInventoryList(query));
    }

    /**
     * 标记确定
     * @param hProjectInventoryMarkModel
     * @return
     */
    @ResponseBody
    @PostMapping("/mark")
    @RequiresPermissions({"halinv:halprowar:edit"})
    public JsonResult applyMark(HProjectInventoryMarkModel hProjectInventoryMarkModel) {

        return proToInvMarkService.applyMark(hProjectInventoryMarkModel);
    }

    /**
     * 获取标记
     * @param hProjectInventoryMarkModel
     * @return
     */
    @ResponseBody
    @PostMapping("/getHProjectInventoryMark")
    @RequiresPermissions({"halinv:halprowar:edit"})
    public JsonResult getHProjectInventoryMark(HProjectInventoryMarkModel hProjectInventoryMarkModel) {

        return proToInvMarkService.getHProjectInventoryMark(hProjectInventoryMarkModel);
    }

    /**
     * 修改标记保存
     * @param hProjectInventoryMarkModel
     * @return
     */
    @ResponseBody
    @PostMapping("/saveMark")
    @RequiresPermissions({"halinv:halprowar:edit"})
    public JsonResult saveMark(HProjectInventoryMarkModel hProjectInventoryMarkModel) {

        return proToInvMarkService.saveMark(hProjectInventoryMarkModel);
    }

    /**
     * 删除标记
     * @param hProjectInventoryMarkModel
     * @return
     */
    @ResponseBody
    @PostMapping("/remove")
    @RequiresPermissions({"halinv:halprowar:del"})
    public JsonResult remove(HProjectInventoryMarkModel hProjectInventoryMarkModel) {

        return proToInvMarkService.removeMark(hProjectInventoryMarkModel);
    }

    /**
     * 提交申请
     * @param hProjectInventoryMarkModel
     * @return
     */
    @ResponseBody
    @PostMapping("/submit")
    @RequiresPermissions({"halinv:halprowar:edit"})
    public JsonResult submit(HProjectInventoryMarkModel hProjectInventoryMarkModel) {

        return proToInvMarkService.submit(hProjectInventoryMarkModel);
    }
}
